<?php $this->load->view('fontend/header'); ?>
<div id="mainleft">
    <h2 class="mainleft">Category Product</h2>
    <ul>
        <?php foreach ($all_categories as $cate) : ?>
        <li <?php if (isset($current_category->category_id) and $cate->category_id == $current_category->category_id) echo 'class="current"';?>>
            <a href="<?php echo site_url($cate->category_url)//link den url den url dung site_url ?>">
                <?php echo $cate->category_name;?>
            </a>
        </li>
        <?php endforeach ?>
    </ul>
    <h2 class="mainleft">search by price</h2>

    <form action="<?php echo site_url('product/search_by_price') ?>" method="get">
        <h2>gia tu:</h2> <input type="text" name="from"/><br/>

        <h2>gia den:</h2><input type="text" name="to"/><br/>
        <input type="submit" value="search"/>
    </form>
</div><!--end mainleft-->
<div id="maincontent">
    <table width="80%">
        <tr>
            <td>Product Name</td>
            <td>Quantily</td>
            <td>Price</td>
            <td>Sub Total</td>
            <td>shipping product</td>
        </tr>
        <?php foreach ($cart as $car) : ?>
        <tr>
            <?php //echo '<pre>'; var_dump($car); echo '</pre>';die;?>
            <td width="30%">
                <img width="200px" src="<?php echo base_url('assets/product_images/product/' . $car['image']);?> "/>
                <br/>
                <?php echo $car['name'];?>
            </td>
            <td width="20%">
                <?php echo form_dropdown('update_quantity', range(0, 10), $car['qty'], 'id="' . $car['rowid'] . '"'); ?>
            </td>
            <td width="20%"><?php echo $car['price'];?></td>
            <td><?php echo $car['subtotal'];?></td>
            <td><?php echo $car['product_shipping']?></td>
        </tr>
        <?php endforeach;?>
        <tr>
            <td>Sub All</td>
            <td></td>
            <td></td>
            <td class="total_current"><?php echo $sub_all;?></td>
        </tr>
        <tr>
            <td>
                <a href="<?php echo site_url('cart/destroy');?>">Empty cart</a>
            </td>
            <td>
                <a href="<?php echo site_url('');?>">tiep tuc mua</a>
            </td>
            <td>
                <a id="checkout" href="javascript:void(0)">Check Out</a>
            </td>
        </tr>
    </table>

    <?php echo form_open();?>
    <table width="80%" id="form_checkout" style="display: none;">
        <tr>
            <td>ho ten</td>
            <td><?php echo form_input('order_name') . form_error('order_name');?></td>
        </tr>
        <tr>
            <td>dia chi mail</td>
            <td><?php echo form_input('order_email') . form_error('order_email');?></td>
        </tr>
        <tr>
            <td>so dien thoai</td>
            <td><?php echo form_input('order_phone_no') . form_error('order_phone_no');?></td>
        </tr>
        <tr>
            <td>phuong thuc nhan hang</td>
            <td><?php echo form_dropdown('order_deliver_method', $options = array('home' => 'nhan tai nha',
                'shop' => 'nhan tai shop'))
                . form_error('order_deliver_method');?></td>
        </tr>
        <tr>
            <td>dia chi nhan hang</td>
            <td><?Php echo form_input('order_address') . form_error('order_address');?></td>
        </tr>
        <tr>
            <td>ghi chu</td>
            <td><?php echo form_textarea('order_comment') . form_error('order_comment');?></td>
        </tr>
        <tr>
            <td><?php echo form_submit('', 'check out');?></td>

            <td><a href="<?php echo site_url('');?>">back home</a></td>
        </tr>
    </table>
    <?php echo form_close();?>

</div><!--end maincontent-->
</div><!--end warper-->
<script type="text/javascript" src="<?php echo base_url('assets/scripts/jquery-1.7.1.min.js');?>"></script>
<script type="text/javascript">
    $("select[name='update_quantity']").change(function () {
        rowid = $(this).attr("id");

        quantity = $(this).find("option:selected").val();
        self = $(this);
        //AJAX
        $.post(
                '<?php echo site_url('cart/ajax_update');?>', // ajax url
                {rowid:rowid, quantity:quantity}, // tham số truyền đi
                function (data) {                                 // nhận kết quả
                    if (data.status == true) {
                        self.parent().next().next().html(data.subtotal);
                        $(".total_current").html(data.total_current);
                    }
                },
                "json"                                          // định dạng dữ liệu mong muốn
        );
    });

    $("#checkout").click(function () {
        $('#form_checkout').fadeIn("slow");//shows,slideDown,fadeIn,fadeOut dung de hien thi
    });
</script>

<?php $this->load->view('fontend/footer'); ?>